package com.nightsoul.hadoop1.test.mapreduce;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import com.nightsoul.hadoop1.test.combiner.MaxTemperatureCombiner;

/**
 * 运行命令：
 * # export HADOOP_CLASSPATH=hadoop1-test-1.0.0-SNAPSHOT.jar
 * # hadoop com.nightsoul.hadoop1.test.mapreduce.NewMaxTemperature /input/010010-99999-2008 /newoutput
 * @author zj
 *
 */
public class NewMaxTemperature {

	public static void main(String[] args) throws Exception {
		if(args.length!=2) {
			System.err.println("Usage: com.nightsoul.hadoop1.test.mapreduce.NewMaxTemperature <input> <output>");
			System.exit(-1);
		}

		Job job = new Job();
		job.setJarByClass(NewMaxTemperature.class);
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		
		job.setMapperClass(NewMaxTemperatureMapper.class);
		job.setReducerClass(NewMaxTemperatureReduce.class);
		//combiner在每个分片的map操作完成后，可能会执行，也可能不会执行，只是一个优化操作
		job.setCombinerClass(MaxTemperatureCombiner.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		
		System.exit(job.waitForCompletion(true) ? 0 : -1);
	}

}
